import _axios from "@/plugins/axios";

// 取消物流运单
export function expressOrderCancel({ cancelReason, expressOrderNo }) {
  return _axios({
    url: "/express/cancelV4",
    method: "post",
    data: {
      cancelReason, // 取消原因
      expressOrderNo, // 运单号
    },
  });
}

// 确认收货
export function expressCompleted(expressOrderNo) {
  return _axios({
    url: "/express/completedV4",
    method: "post",
    data: {
      expressOrderNo,
    },
  });
}

// 确认物流运单
export function expressOrderConfirm(expressOrderNo) {
  return _axios({
    url: "/express/confirm",
    method: "post",
    data: {
      expressOrderNo,
    },
  });
}

// 预创建物流运单商品清单
export function cargoList(paramKey) {
  return _axios({
    url: "/express/cargo/select",
    method: "get",
    params: {
      paramKey,
    },
  });
}

// 提交运单
export function expressOrderCreate({
  addressId,
  expressOrderNo,
  remarks,
  routeId,
  serviceItemIdList,
  insuranceId, //保险服务
  couponCustomerId,
  skipPrepaid,
  taxNumber
}) {
  return _axios({
    // url: "/express/submitV2",
    // url: "/express/submitV4",
    url: "/express/submitV5",
    method: "post",
    data: {
      addressId, // 地址ID
      expressOrderNo, // 预创建物流运单返回的ID
      remarks, // 运单备注
      routeId, // 物流路线ID
      serviceItemIdList, // 包装服务项IDS   
      insuranceId, //保险服务
      couponCustomerId,
      skipPrepaid,
      taxNumber //税号
    },
  });
}

// 我的物流运单分页列表查询
export function expressOrderList({ expressOrderNo, pageNo, pageSize, status, createTimeStart, createTimeEnd, lotteryActivity }) {
  return _axios({
    url: "/express/listV2",
    method: "get",
    params: {
      expressOrderNo, // 运单号
      pageNo, // pageNo,示例值(1)
      pageSize, // pageSize,示例值(10)
      status, // 运单状态
      createTimeStart,
      createTimeEnd,
      lotteryActivity
    },
  });
}

// 物流路线查询查询
export function logisticsRoutes() {
  return _axios({
    url: "/logistics/route/list",
    method: "get",
  });
}

// 查询可寄送的物流列表
export function expressLogisticsList(id, addressId, currency, serviceItemIdList = []) {
  return _axios({
    // url: `/express/${id}/route`,
    url: `/express/${id}/route2`,
    method: "get",
    params: {
      addressId,
      currency,
      serviceItemIdList: serviceItemIdList.join(',')
    },
  });
}

// 包裹分页列表查询
export function parcelList({ isParcelable, orderNo, pageNo, pageSize, status, createTimeStart, createTimeEnd }) {
  return _axios({
    url: "/order/stored/list@2",
    method: "get",
    params: {
      isParcelable,
      orderNo, // 订单号
      pageNo, // pageNo,示例值(1)
      pageSize, // pageSize,示例值(10)
      status, // 运单状态
      createTimeStart,
      createTimeEnd
    },
  });
}

export function expressSelect() {
  return _axios({
    url: "/express/cargo/select",
    method: "post",
    data: {},
  });
}

// 预创建物流运单
export function expressOrderPre(orderNoList, orderAddressId) {
  return _axios({
    url: "/express/create@2",
    method: "post",
    data: {
      orderItemIdList: orderNoList, // 需要创建运单的订单号
      orderAddressId,
    },
  });
}

// 仓储服务类目查询
export function expressOrderService() {
  return _axios({
    url: "/logistics/service/item/list",
    method: "get",
  });
}

// 去确认物流运单
export function expressOrderToConfirm(expressOrderNo) {
  return _axios({
    url: "/expressOrder/toConfirm",
    method: "get",
    params: {
      expressOrderNo,
    },
  });
}

// 确定支付差价
export function submitConfirming(data) {
  return _axios({
    url: "/express/submit-confirming",
    method: "post",
    data,
  });
}

// 获取运单的物流追踪信息（国际）
export function expressOrderQueryLogisticsTrace(expressNo) {
  return _axios({
    url: "/logistics//track/intl",
    method: "get",
    params: {
      expressNo,
    },
  });
}

// 运单包裹-分页列表查询
export function expressParcelList(expressNo, pageNo = 1, pageSize = 1000) {
  return _axios({
    url: "/expressOrder/expressParcelList",
    method: "get",
    params: {
      expressNo,
      pageNo,
      pageSize,
    },
  });
}

// 物流运单详情
export function expressOrderDetails(expressOrderNo, currency) {
  return _axios({
    url: "/express/detail",
    method: "get",
    params: {
      expressOrderNo,
      currency,
    },
  });
}

// 确定运单详情
export function confirmingDetails(expressOrderNo, currency, couponCustomerId) {
  return _axios({
    url: "/express/confirming",
    method: "post",
    data: {
      expressOrderNo,
      currency,
      couponCustomerId //优惠券
    },
  });
}

// 仓库地址查询
export function expressOrderAddressList() {
  return _axios({
    url: "/address/warehouse/default",
    method: "get",
  });
}

// 商品详情、多包裹
export function detailList(expressOrderNo, currency) {
  return _axios({
    url: "/express/detail/v2",
    method: "get",
    params: {
      expressOrderNo,
      currency,
    },
  });
}

// 运单试算
export function calculate({
  couponCustomerId,
  addressId,
  expressOrderNo,
  remarks,
  routeId,
  serviceItemIdList,
  insuranceId,
  // skipPrepaid
}) {
  return _axios({
    url: "/express/calculate",
    method: "post",
    data: {
      couponCustomerId,
      addressId, // 地址ID
      expressOrderNo, // 预创建物流运单返回的ID
      remarks, // 运单备注
      routeId, // 物流路线ID
      serviceItemIdList, // 包装服务项IDS   
      insuranceId, //保险服务
      // skipPrepaid
    },
  });
}

// 子单退货-取消退货
export function returnOrderCancel(returnOrderId) {
  return _axios({
    url: "/order/returnOrderCancel",
    method: "get",
    params: {
      returnOrderId
    },
  });
}
// 子单退货-费用
export function returnOrderEstimate(orderItemId) {
  return _axios({
    url: "/order/returnOrderEstimate",
    method: "get",
    params: {
      orderItemId
    },
  });
}
// 子单退货-申请
export function returnOrderApply({
  orderItemId,
  returnReason,
  agreement
}) {
  return _axios({
    url: "/order/returnOrderApply",
    method: "post",
    data: {
      orderItemId,
      returnReason,
      agreement
    },
  });
}
// 运单列表-物流信息
export function queryLogisticsIntl(expressNo) {
  return _axios({
    url: 'logistics/track/intl',
    method: 'get',
    params: {
      expressNo, // 快递追踪号
    }
  })
}


// 运单获取留言板列表
export function getListExpressMessage(expressOrderNo) {
  return _axios({
    url: '/express/messages',
    method: 'get',
    params: {
      expressOrderNo
    }
  })
}


// 支付结果查询运单是否首单
export function searchOrderFirst(expressOrderNo) {
  return _axios({
    url: '/express/lottery',
    method: 'get',
    params: {
      expressOrderNo
    }
  })
}


// 免运费活动-活动详情
export function getActivityDetail(activityId) {
  return _axios({
    url: '/lotteryActivity/detail',
    method: 'get',
    params: {
      activityId
    }
  })
}

// 免运费活动-金币奖励记录
export function getGoldRecord(activityId) {
  return _axios({
    url: '/lotteryActivity/gold/record',
    method: 'get',
    params: {
      activityId
    }
  })
}


// 免运费活动-好友列表
export function getInviteUser(activityId) {
  return _axios({
    url: '/lotteryActivity/invite/user',
    method: 'get',
    params: {
      activityId
    }
  })
}

// 免运费活动-活动详情
export function lotteryDetail(activityId) {
  return _axios({
    url: '/lotteryActivity/detail',
    method: 'get',
    params: {
      activityId
    }
  })
}

// 免运费活动-抽奖
export function lotteryDraw(activityId) {
  return _axios({
    url: '/lotteryActivity/draw',
    method: 'get',
    params: {
      activityId
    }
  })
}


// 免运费活动-点击统计-活动
export function lotteryClick({
  activityId,
  clientType = 1,//请求类型：1-PC;2-H5;3-APP	
  operateType
}) {
  return _axios({
    url: "/lotteryActivity/click/save",
    method: "post",
    data: {
      activityId,
      clientType,
      operateType
    },
  });
}

// 延长保管期
export function extendTime(data) {
  return _axios({
    url: '/order/storage/extend',
    method: 'post',
    data: data
  })
}

// 取消延长保管订单
export function cancelExtendOrder(params) {
  return _axios({
    url: '/order/storage/cancelOrder',
    method: 'get',
    params: params
  })
}